package pers.corvey.studyjava.model.form;

import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import pers.corvey.studyjava.model.Course;
import pers.corvey.studyjava.util.ToStringUtils;

public class CourseForm implements MyValidatable {

    @NotNull(message="课程名称不能为空")
    @Size(max=Course.TITLE_MAX_LEN, message="课程名称不能超过20个汉字")
    private String title;
    
    private String description;
    
    @NotNull(message="课程分类编号不能为空")
    private String categoryId;
    
    public CourseForm() {}

    public Course toCourse() {
        Course course = new Course();
        course.setTitle(getTitle());
        course.setDescription(getDescription());
        course.setCategoryId(getCategoryId());
        return course;
    }
    
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(String categoryId) {
        this.categoryId = categoryId;
    }
    
    @Override
    public String toString() {
        return ToStringUtils.objectToString(this);
    }
}
